//
//  MeetingScrollView.m
//  Gxj
//
//  Created by 刘伟 on 2017/9/2.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "MeetingScrollView.h"

@interface MeetingScrollView () <SDCycleScrollViewDelegate,PYSearchViewControllerDataSource>
@property(nonatomic, strong) PYSearchViewController *searchViewController;//搜索
@property(nonatomic, strong) UIScrollView * demoContainerView;//滚动视图
//搜索条按钮
@property(nonatomic, strong) UIButton * searchButton;
@end

@implementation MeetingScrollView

- (instancetype)init
{
    if (self = [super init]) {
        
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self showMeetingScroll];
    }
    return self;
}

- (void)showMeetingScroll
{
    //创建滚动视图
    _demoContainerView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, kHeightScale(157))];
    //滚动视图的位置
    _demoContainerView.contentSize = CGSizeMake(UIScreenWidth,kHeightScale(157));
    
    //添加到主视图中
    [self addSubview:_demoContainerView];
    
    NSArray*arr=@[@"banner",@"ditu",@"banner"];
    //本地图片显示轮播图
    SDCycleScrollView*view=[SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, UIScreenWidth, kHeightScale(157)) shouldInfiniteLoop:YES imageNamesGroup:arr];
    view.delegate=self;
    //轮播图页数设置----小点
    view.pageControlStyle = SDCycleScrollViewPageContolStyleClassic;
    //轮播图时间间隔
    view.autoScrollTimeInterval = 2.0;
    [_demoContainerView addSubview:view];
    view.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    _navigationView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, kHeightScale(64))];
    _navImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, kHeightScale(64))];
    _navImage.userInteractionEnabled = YES;
    
//    UIButton *fenleiBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    fenleiBtn.frame = CGRectMake(kWidthScale(23), kHeightScale(25), kWidthScale(22), kHeightScale(22));
//    [fenleiBtn setBackgroundImage:[UIImage imageNamed:@"fenlei"] forState:0];
//    [fenleiBtn addTarget:self action:@selector(clickClassiFication:) forControlEvents:UIControlEventTouchUpInside];
//    [_navImage addSubview:fenleiBtn];
    
    //消息列表响应
    UIButton * news = [[UIButton alloc] initWithFrame:CGRectMake(kWidthScale(344), kHeightScale(25), kWidthScale(20), kHeightScale(20))];
    [news setImage:[UIImage imageNamed:@"xiaoxiti"] forState:UIControlStateNormal];
    [news addTarget:self action:@selector(tiaozhuangnews) forControlEvents:UIControlEventTouchUpInside];
    
    [_navImage addSubview:news];
    
//    搜索条按钮
    _searchButton=[[UIButton alloc] initWithFrame:CGRectMake(kWidthScale(15), kHeightScale(20), UIScreenWidth - kWidthScale(60), kHeightScale(32))];
    [_searchButton addTarget:self action:@selector(shuaxinShearch) forControlEvents:UIControlEventTouchUpInside];
    [_searchButton setImage:[UIImage imageNamed:@"sousuo-2.jpg"] forState:(UIControlStateNormal)];
    [_searchButton setTitle:@"  搜索会议" forState:UIControlStateNormal];
    _searchButton.titleLabel.font = [UIFont systemFontOfSize:kWidthScale(15)];
    [_searchButton setTitleColor:[UIColor colorWithWhite:1 alpha:0.7] forState:0];
    _searchButton.layer.cornerRadius = kWidthScale(12);
    _searchButton.layer.masksToBounds = YES;
    _searchButton.backgroundColor = [UIColor colorWithWhite:0.1 alpha:0.4];
    _searchButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    _searchButton.titleEdgeInsets = UIEdgeInsetsMake(0, 8, 0, 0);
    _searchButton.imageEdgeInsets = UIEdgeInsetsMake(0, 8, 0, 0);
    _searchButton.titleLabel.textAlignment = NSTextAlignmentLeft;
    [_navImage addSubview:_searchButton];
    
    [_navigationView addSubview:_navImage];
    
    [_demoContainerView addSubview:_navigationView];
    
    //创建shearch搜索内容，在搜索条内展示出来的比较热门的
    NSArray*hostArr=@[@"索大大",@"王奎卿",@"杨凌云",@"牛文勤",@"垒哥",@"刘总",@"任总"];
    //创建Shearch视图显示
    _searchViewController=[PYSearchViewController searchViewControllerWithHotSearches:hostArr searchBarPlaceholder:@"天创网络" didSearchBlock:^(PYSearchViewController * searchViewController,UISearchBar * searchBar,NSString * searchText){
        //自动完成搜索时调用此块
        //如：推送到视图控制器
        if (self.searchPopBlock) {
            self.searchPopBlock(searchViewController);
        }
    }];
    //设置代理r
    _searchViewController.dataSource=self;
    //设置searchResultShowMode
    _searchViewController.searchResultShowMode = PYSearchResultShowModeEmbed;
    // 2.设置searchResultController
    _searchViewController.searchResultController = [[UIViewController alloc ] init ];
    //设置hotSearchStyle
    _searchViewController.hotSearchStyle = PYHotSearchStyleColorfulTag;
    // Set searchHistoryStyle
    _searchViewController.searchHistoryStyle = PYSearchHistoryStyleBorderTag;
    //设置searchHistoriesCount
    _searchViewController.searchHistoriesCount = 6 ;
    // Set searchResultShowMode
    _searchViewController.searchResultShowMode = PYSearchResultShowModeEmbed;
    // Set searchSuggestionHidden
    _searchViewController.searchSuggestionHidden = YES ;
}

//消息列表按钮响应
- (void)tiaozhuangnews{
    if (self.newsPushBlock) {
        self.newsPushBlock(YES);
    }
}

- (void)didClickCancel:(PYSearchViewController *)searchViewController {
    if (self.searchPopBlock) {
        self.searchPopBlock(searchViewController);
    }
}

- (void)shuaxinShearch
{
    if (self.searchPushBlock)
    {
        self.searchPushBlock(_searchViewController);
    }
}

- (void)clickClassiFication:(UIButton *)sender
{
    if (self.classificationPushBlock) {
        self.classificationPushBlock(YES);
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
